package com.kl.schedule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class AppCoreTask {

    // 打印
    private static final Logger log = LoggerFactory.getLogger(AppCoreTask.class);
    // 时间格式化
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    /**
     * {秒} {分} {时} {日} {月} {周} {年(可选)}
     * 要求在17:37分打印一句话
     */
    @Scheduled(cron = "0 37 17 * * ? ")
    public void task() {
        log.info("开启定时任务: " + new Date());
    }


    /**
     * 每5秒执行一次
     */
    @Scheduled(fixedRate = 5000)
    public void jobTask() {
        log.info("任务执行时间: " + dateFormat.format(new Date()));
    }

}


